﻿using Sys.Common;
using Sys.Core.Gen;
using Sys.Core.Tour;
using Sys.Core.Sys;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            var title = SettingBll.I.GetContent("Website", "SiteName");
            var keywords = SettingBll.I.GetContent("Website", "Keywords");
            var description = SettingBll.I.GetContent("Website", "Description");

            Home mas = Master as Home;
            mas.SetHead(title, keywords, description);
        }
    }

    public string GetIconCss()
    {
        string fipath = Server.MapPath("~/public/easyui/themes/myicons");

        DirectoryInfo di = new DirectoryInfo(fipath);
        FileInfo[] flist = di.GetFiles();

        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        foreach (FileInfo item in flist)
        {
            sb.AppendLine(".icon-" + item.Name.Replace(item.Extension, string.Empty) + " {");
            sb.AppendLine("    background: url('myicons/" + item.Name + "') no-repeat center center;");
            sb.AppendLine("}");
        }

        return sb.ToString();
    }

    public string GetFocu()
    {
        var list = FocuBll.I.SortEntities.Where(m => m.Group.Equals("Home") && m.IsVisible);

        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        sb.Append("<ul>");

        foreach (var item in list)
        {
            string link = "href='javascript:void(0)'";
            if (!string.IsNullOrEmpty(item.Link))
            {
                link = "href='" + item.Link + "' target='_blank'";
            }
            sb.Append("<li><a " + link + ">");
            sb.Append("<img src='userfiles/focu/" + item.Img + "' />");
            sb.Append("</a></li>");
        }

        sb.Append("</ul>");

        return sb.ToString();
    }

    public string LeftButtonImage(int index)
    {
        var entities = FocuBll.I.SortEntities.Where(m => m.Group.Equals("LeftButton") && m.IsVisible);

        var model = entities.Skip(index).FirstOrDefault();

        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        if (model != null)
        {
            sb.Append("<p><a href='" + (string.IsNullOrEmpty(model.Link) ? "javascript:void(0)" : model.Link) + "' target='_blank'><img src='userfiles/focu/" + model.Img + "' /></a></p>");
        }
        else
        {
            sb.Append("<p><a href='javascript:void(0)'><img width='246' height='178' src='userfiles/focu/null.png' /></a></p>");
        }

        return sb.ToString();
    }

    public string GetScenic()
    {
        var list = ScenicBll.I.Entities.OrderByDescending(m => m.Top).ThenByDescending(m => m.UpdateTime);

        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        sb.Append("<ul>");

        foreach (var item in list.Take(8))
        {
            sb.Append("<li>");
            sb.Append("<a href='Scenic.aspx?id=" + item.ID + "' target='_blank'>");
            sb.Append("<span class='pic'><img src='userfiles/scenic/home/" + item.Img + "' /></span>");
            sb.Append("<span class='holist'>" + item.Name + "</span> ");
            sb.Append("<span class='txt'>" + StringHelper.CutString(StringHelper.NoHTML(item.Content), 50) + "</span>");
            sb.Append("</a>");
            sb.Append("</li>");
        }

        sb.Append("</ul>");

        return sb.ToString();
    }

    public string GetProgram()
    {
        var list = ProgramBll.I.Entities.OrderByDescending(m => m.UpdateTime);

        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        sb.Append("<ul>");

        foreach (var item in list.Take(8))
        {
            string img = ImageBll.I.GetFront("Program", item.ID);
            sb.Append("<li>");
            sb.Append("<a href='Program.aspx?id=" + item.ID + "' target='_blank'>");
            sb.Append("<span class='pic'><img src='userfiles/program/home/" + img + "' /></span>");
            sb.Append("<span class='holist'>" + item.Name + "</span> ");
            sb.Append("<span class='txt'>" + StringHelper.CutString(StringHelper.NoHTML(item.Content), 50) + "</span>");
            sb.Append("</a>");
            sb.Append("</li>");
        }

        sb.Append("</ul>");

        return sb.ToString();
    }

    public string GetRural()
    {
        var list = RuralBll.I.Entities.OrderByDescending(m => m.UpdateTime);

        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        sb.Append("<ul>");

        foreach (var item in list.Take(8))
        {
            string img = ImageBll.I.GetFront("Rural", item.ID);
            sb.Append("<li>");
            sb.Append("<a href='Rural.aspx?id=" + item.ID + "' target='_blank'>");
            sb.Append("<span class='pic'><img src='userfiles/rural/home/" + img + "' /></span>");
            sb.Append("<span class='holist'>" + item.Name + "</span> ");
            sb.Append("<span class='txt'>" + StringHelper.CutString(StringHelper.NoHTML(item.Content), 50) + "</span>");
            sb.Append("</a>");
            sb.Append("</li>");
        }

        sb.Append("</ul>");

        return sb.ToString();
    }

    public string GetPlacard()
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        var list = NewBll.I.NewsByTag("Placard").Take(2);

        string img = "userfiles/website/" + SettingBll.I.GetContent("Website", "VideoFront");
        string flv = "../userfiles/website/" + SettingBll.I.GetContent("Website", "VideoFlv");

        sb.Append("<p>");
        sb.Append("<embed src=\"public/jwplayer.swf\"");
        sb.Append("id=\"jwplayer\" name=\"jwplayer\" width=\"218\" height=\"140\"");
        sb.Append("type=\"application/x-shockwave-flash\" allowfullscreen=\"true\"");
        sb.Append("pluginspage=\"http://www.macromedia.com/go/getflashplayer\"");
        sb.Append("flashvars=\"image=" + img + "&controlbar=none&file=" + flv + "\" />");
        sb.Append("</p>");

        sb.Append("<ul>");

        foreach (var item in list)
        {
            sb.Append("<li>");
            sb.Append("<a href='New.aspx?id=" + item.ID + "' target='_blank'>" + StringHelper.CutString(item.Name, 30) + "</a>");
            sb.Append("</li>");
        }

        sb.Append("</ul>");

        return sb.ToString();
    }

    public string GetNewsByTag(string tag)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        var list = NewBll.I.NewsByTag(tag).Take(6).ToList();

        sb.Append("<ul>");

        foreach (var item in list)
        {
            sb.Append("<li><p>·");
            sb.Append("<a href='New.aspx?id=" + item.ID + "' target='_blank'>" + StringHelper.CutString(item.Name, 58) + "</a>");
            sb.Append("</p></li>");
        }

        sb.Append("</ul>");

        return sb.ToString();
    }

    public string GetNewsByTag(string tag, int rows)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        var list = NewBll.I.NewsByTag(tag).Take(rows).ToList();

        sb.Append("<ul>");

        for (int i = 0; i < list.Count; i++)
        {
            var item = list[i];

            switch (i + 1)
            {
                case 1: sb.Append("<li class='blank'>"); break;
                case 2: sb.Append("<li class='orange'>"); break;
                case 3: sb.Append("<li class='yellow'>"); break;
                default: sb.Append("<li class='gray'>"); break;
            }

            sb.Append("<span>" + (i + 1) + "</span>");
            sb.Append("<a href='New.aspx?id=" + item.ID + "' target='_blank'>" + StringHelper.CutString(item.Name, 28) + "</a>");
            sb.Append("</li>");
        }

        sb.Append("</ul>");

        return sb.ToString();
    }

    public string GetTravel()
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        var list = TravelBll.I.Entities.OrderByDescending(m => m.UpdateTime).Take(6).ToList();

        sb.Append("<ul>");

        for (int i = 0; i < list.Count; i++)
        {
            var item = list[i];

            switch (i + 1)
            {
                case 1: sb.Append("<li class='blank'>"); break;
                case 2: sb.Append("<li class='orange'>"); break;
                case 3: sb.Append("<li class='yellow'>"); break;
                default: sb.Append("<li class='gray'>"); break;
            }

            sb.Append("<span>" + (i + 1) + "</span>");
            sb.Append("<a href='Travel.aspx?id=" + item.ID + "' target='_blank'>" + StringHelper.CutString(item.Name, 28) + "</a>");
            sb.Append("</li>");
        }

        sb.Append("</ul>");

        return sb.ToString();
    }

    public string GetRoute()
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        var entities = RouteBll.I.Entities.OrderByDescending(m => m.Top).ThenByDescending(m => m.UpdateTime);

        var list = entities.Take(7).ToList();

        if (list.Count > 0)
        {
            sb.Append("<div class='rou_pic'>");
            sb.Append("<p><a href='Route.aspx?id=" + list[0].ID + "' target='_blank'><img src='userfiles/route/home/" + list[0].Img + "' /></a></p>");
            sb.Append("<div>");
            sb.Append("<strong><a href='Route.aspx?id=" + list[0].ID + "' class='white' target='_blank'>" + list[0].Name + "</a></strong>");
            sb.Append("<span><font>" + list[0].Price + "</font>/人起</span>");
            sb.Append("</div>");
            sb.Append("</div>");

            list.Remove(list[0]);

            sb.Append("<ul>");

            foreach (var item in list)
            {
                sb.Append("<li><p>·<a href='Route.aspx?id=" + item.ID + "' target='_blank'>" + StringHelper.CutString(item.Name, 42) + "</a></p><span><font>" + item.Price + "</font>/人起</span></li>");
            }

            sb.Append("</ul>");
        }

        return sb.ToString();
    }

    public string GetMeeting()
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        var entities = MeetingBll.I.Entities.OrderByDescending(m => m.UpdateTime);

        var list = entities.Take(7).ToList();

        if (list.Count > 0)
        {
            string img = ImageBll.I.GetFront("Meeting", list[0].ID);

            sb.Append("<div class='rou_pic'>");
            sb.Append("<p><a href='Meeting.aspx?id=" + list[0].ID + "' target='_blank'><img src='userfiles/meeting/home/" + img + "' /></a></p>");
            sb.Append("<div>");
            sb.Append("<strong><a href='Meeting.aspx?id=" + list[0].ID + "' class='white' target='_blank'>" + list[0].Name + "</a></strong>");
            sb.Append("<span><font>" + list[0].Price + "</font>/天起</span>");
            sb.Append("</div>");
            sb.Append("</div>");

            list.Remove(list[0]);

            sb.Append("<ul>");

            foreach (var item in list)
            {
                sb.Append("<li><p>·<a href='Meeting.aspx?id=" + item.ID + "' target='_blank'>" + StringHelper.CutString(item.Name, 42) + "</a></p><span><font>" + item.Price + "</font>/天起</span></li>");
            }

            sb.Append("</ul>");
        }

        return sb.ToString();
    }

    public string GetCar()
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();

        var entities = CarBll.I.Entities.OrderByDescending(m => m.UpdateTime);

        var list = entities.Take(7).ToList();

        if (list.Count > 0)
        {
            string img = ImageBll.I.GetFront("Car", list[0].ID);

            sb.Append("<div class='rou_pic'>");
            sb.Append("<p><a href='Car.aspx?id=" + list[0].ID + "' target='_blank'><img src='userfiles/car/home/" + img + "' /></a></p>");
            sb.Append("<div>");
            sb.Append("<strong><a href='Car.aspx?id=" + list[0].ID + "' class='white' target='_blank'>" + list[0].Name + "</a></strong>");
            sb.Append("<span><font>" + list[0].Price + "</font>/天起</span>");
            sb.Append("</div>");
            sb.Append("</div>");

            list.Remove(list[0]);

            sb.Append("<ul>");

            foreach (var item in list)
            {
                sb.Append("<li><p>·<a href='Car.aspx?id=" + item.ID + "' target='_blank'>" + StringHelper.CutString(item.Name, 42) + "</a></p><span><font>" + item.Price + "</font>/天起</span></li>");
            }

            sb.Append("</ul>");
        }

        return sb.ToString();
    }
}


